﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zzj.Utils
{
    /// <summary>
    /// 继承所有的读卡器读取身份证
    /// </summary>
    public class IdCardRead
    {
        /// <summary>
        /// 读取身份证信息
        /// </summary>
        /// <returns> </returns>
        public static String ReadCardInfo()
        {
            String facId = "";
            string cardDevice = (string)App.getConfig().IDCardDevice;
            if ("0".Equals(cardDevice))//使用默认身份证号
            {
                facId = App.getConfig().IDCardCode;
            }
            else
            {
                string CardReaderDeviceType = App.getConfig().CardReaderDeviceType;//获取使用的读卡器品牌
                if (CardReaderDeviceType == "1")//神思读卡器
                {
                    facId = SSReadCardInfo();
                }
                else if (CardReaderDeviceType == "2")//精伦读卡器
                {
                    JLCardInfo jLCardInfo = JLReadCardInfo();
                    if (jLCardInfo != null)
                    {
                        facId = jLCardInfo.CardNo;
                    }
                }
            }

            return facId;
        }

        /// <summary>
        /// 神思读卡器读取信息,返回身份证号
        /// </summary>
        public static string SSReadCardInfo()
        {
            String facId = "";
            StringBuilder IdCardInfo = new StringBuilder(409600);
            int ret = CommonInterface.SdtReadCard(0, 1, IdCardInfo, 0);
            if (ret == 0)
            {
                string[] CardInfo = IdCardInfo.ToString().Split(':');

                String name = CardInfo[1];
                String idNum = CardInfo[9];
                facId = idNum;//身份证号
            }
            return facId;
        }

        /// <summary>
        /// 精伦读卡获取信息
        /// </summary>
        /// <returns> </returns>
        public static JLCardInfo JLReadCardInfo()
        {
            JLCardInfo jLCardInfo = JLIDcardread.ReadIDcardEnhanced();

            return jLCardInfo;
        }
    }
}